package com.example.kotlinlearn.kotlinLearn.review

import android.os.Build
import androidx.annotation.RequiresApi
import java.sql.Time
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.*
import kotlin.concurrent.timer

lateinit var a:Number

@RequiresApi(Build.VERSION_CODES.O)
fun main(){
    for (i in 0..10000){
        getData()
        println("$i--------------"+ getTime())
    }

    a = 45
    when(a){
        is Int -> {
            println("Int")
        }
        is Double -> {
            println("String")
        }
    }

    when(13) {
        1 -> println("aa")
        else -> println("jj")
    }


}

//不带参数的判断
fun getNum(num:Int) = when {
    num <= 10 -> println("djadk")
    num < 100 -> println("1313")
    else -> println("12321")
}

@RequiresApi(Build.VERSION_CODES.O)
fun getData(){
    val current = LocalDateTime.now()
    val time = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")
    val timed = current.format(time)
    val num = (0..10).random()
    when (num){
        0 ->  println(timed)
        1 ->  println("1")
        2 -> println("2")
        3 -> println("3")
        4 -> println("4")
        5 -> println("5")
        6 -> println("6")
        7 -> println("7")
        8 -> println("8")
        else -> println("不知道")
    }
}

@RequiresApi(Build.VERSION_CODES.O)
fun getTime(): String? {
    val current = LocalDateTime.now()
    val time = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")
    val timed = current.format(time)
    return timed
}